<hr>
<p>title: 55.jump-game<br>date: 2023-03-01 20:32:39<br>tags:</p>
<pre><code>- LeeCode
</code></pre><p>categories:</p>
<pre><code>- LeeCode
</code></pre><p>hidden: true</p>
<h2 id="cateHidden-false"><a href="#cateHidden-false" class="headerlink" title="cateHidden: false"></a>cateHidden: false</h2><h3 id="Description"><a href="#Description" class="headerlink" title="Description"></a>Description</h3><blockquote>
<p>You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position.</p>
<p>Return true if you can reach the last index, or false otherwise.</p>
</blockquote>
<h3 id="Example"><a href="#Example" class="headerlink" title="Example"></a>Example</h3><blockquote>
<p>Input: nums = [2,3,1,1,4]<br>Output: true<br>Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.</p>
</blockquote>
<h3 id="Solution"><a href="#Solution" class="headerlink" title="Solution"></a>Solution</h3><pre><code class="lang-js">/**
 * @param {number[]} nums
 * @return {boolean}
 */
var canJump = function (nums) {
    if (nums.length === 1) return true;
    const backtracking = (current) =&gt; {
        if (current &lt; nums[0]) return true;
        for (let i = 0; i &lt; current; i++) {
            if (nums[i] &gt;= current - i) {
                return backtracking(i);
            }
        }
        return false;
    }
    return backtracking(nums.length - 1);
}
</code></pre>
